const encryption = require('../utils/encryption')
class WechatServer {
	constructor(http) {
		this.http = http;
	}
	/**
	 * @description 验证token是否正确
	 */
	token() {
		let {
			signature = '', timestamp = '', nonce = '', echostr = ''
		} = this.http.queryStringParameters
		let token = "baiguikeji";
		let askey = "3lgzPmLkg0ehLDCiwvo4g0kKjc5Rm2NsRKm6bc5zlZH";
		// 验证token
		let str = [token, timestamp, nonce].sort().join('')
		let sha1 = encryption.sha1(str)
		if (sha1 !== signature) {
			return false
		} else {
			return echostr
		}
	}
}

module.exports = WechatServer
